package com.hysf.project1;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Primary
@Data
public class PersonMysqlDao implements PersonDao {
	@Autowired
	@Qualifier ("jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public List<Person> findAll() {
		String sql = "SELECT * FROM person";
		return jdbcTemplate.query(sql, new MyMapper());
	}
	
	@Override
	public Person addPerson(Person person) {
		String sql = "INSERT INTO person (id,name) VALUES (?,?)";
		jdbcTemplate.update(sql, person.getId(), person.getName());
		return person;
	}
}
